package com.suxin.shiro.realm;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;

/**
 * @author Tang
 * @classname MainTest
 * @description [  ]
 * @date 2021/3/20 13:30
 */
public class MainTest {

    public static void main(String[] args) {

        DefaultSecurityManager manager = new DefaultSecurityManager();
        manager.setRealm(new MyRealm());

        SecurityUtils.setSecurityManager(manager);
        Subject subject = SecurityUtils.getSubject();

        try {
            System.out.println("是否认证：" + subject.isAuthenticated());
            subject.login(new UsernamePasswordToken("name","tang"));
            System.out.println("是否认证：" + subject.isAuthenticated());
        } catch (Exception e) {
            System.err.println("认证失败....");
        }

    }

}